<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('月度监控') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('年月')" prop="days">
        <DatePicker v-model="daysTime" type="monthrange" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:monthlyMonitoring:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:monthlyMonitoring:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t('导出') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="dealMonthlyMonitoringList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('年月')" align="center" prop="days">
        <template slot-scope="scope">
          <span class="link-type" @click="updateHandle(scope.row)">{{ parseTime(scope.row.days, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('累计土地成本') + $t('金额单位')" align="center" prop="accumulatedLandCost">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.accumulatedLandCost, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('土地成本调整项') + $t('金额单位')" align="center" prop="landCostAdjustmentItem">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.landCostAdjustmentItem, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('除地价外直接投资') + $t('金额单位')" align="center" prop="additionToLandPrice">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.additionToLandPrice, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('累计费用总额') + $t('金额单位')" align="center" prop="totalAccumulatedExpenses">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.totalAccumulatedExpenses, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('累计总成本') + $t('金额单位')" align="center" prop="totalCumulativeCost">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.totalCumulativeCost, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['deal:monthlyMonitoring:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['deal:monthlyMonitoring:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改月度监控对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealMonthlyMonitoringForm ref="dealMonthlyMonitoringForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listDealMonthlyMonitoring, delDealMonthlyMonitoring } from '@/api/deal/estate/monthlyMonitoring/dealMonthlyMonitoring'
import dealMonthlyMonitoringForm from './dealMonthlyMonitoringForm.vue'
export default {
    components: {
        dealMonthlyMonitoringForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 月度监控表格数据
          dealMonthlyMonitoringList: [],
          // 年月日期范围
          daysTime: [],
          // 弹出层标题
          title: '月度信息',
          // 是否显示弹出层
          formOpen: false,
        // 亮灯分类字典
        classificationOfLightsOptions: [],

          // 查询参数
          queryParams: {
            dealId: this.$route.query.id,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {
          },
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
      this.getDicts('classification_of_lights').then(response => {
          this.classificationOfLightsOptions = response.data
      })
  },
  methods: {
    /** 查询月度监控列表 */
    getList() {
        this.loading = true
      if (this.daysTime != null && this.daysTime.length > 1) {
        this.queryParams.startDate = this.daysTime[0]
        this.queryParams.endDate = this.daysTime[1]
      } else {
        this.queryParams.startDate = undefined
        this.queryParams.endDate = undefined
      }
        listDealMonthlyMonitoring(this.queryParams).then(response => {
            this.dealMonthlyMonitoringList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 亮灯分类字典翻译
    classificationOfLightsFormat(row) {
      return this.selectDictLabel(this.classificationOfLightsOptions, row.classificationOfLights)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,

            dealId: undefined,

            days: undefined,

            classificationOfLights: undefined,

            accumulatedLandCost: undefined,

            landCostAdjustmentItem: undefined,

            additionToLandPrice: undefined,

            totalAccumulatedExpenses: undefined,

            totalCumulativeCost: undefined,

            valueGoodsPushed: undefined,

            numberSetsPushedDisks: undefined,

            soldACycle: undefined,

            thisMonthSubscribeCycle: undefined,

            thisMonthSubscribeAverage: undefined,

            totalSubscription: undefined,

            totalContractAmount: undefined,

            accumulatedContractedArea: undefined,

            averageContractUnitPrice: undefined,

            accumulatedRecoveryFunds: undefined,

            totalLineCredit: undefined,

            briefAnalysis: undefined,

            redAndYellowDeal: undefined,

            needCommunicate: undefined,

            remark: undefined,

            delFlag: undefined,

            createBy: undefined,

            createTime: undefined,

            updateBy: undefined,

            updateTime: undefined

        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.daysTime = []
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.dealMonthlyMonitoringForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      debugger
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.dealMonthlyMonitoringForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delDealMonthlyMonitoring(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
      this.downLoadExcel('/monthlyMonitoring/dealMonthlyMonitoring/export', this.queryParams)
    }
  }
}
</script>
